# CONFIGURATION
IN_FILEpre=test

# 10^9: 1000000000
ITERATIONS=1000000000
THREADS="2 4 8 16"	# Listar com quantas threads rodar os algoritmos paralelos

# Black Scholes
BK_IN=" 100 110 10 1 1 "

# AUTOMATIC FROM HERE
OUT_FILEpre=$IN_FILEpre'_out'

RunTests(){
	N=$1
	for (( c=1; c <= N; c++ ))
	do
		echo '#####' Test $c '#####'
		echo '#####' Test $c '#####' >> $OUT_FILE
		time -p ( ./PiCalc < $IN_FILE >> $OUT_FILE ) 2>> $OUT_FILE
		echo '> Test ' $c 'comple.'
	done
}

PrepareAndRunTests(){
	# $1 = Algorithm to execute [A, B, C]
	# $2 = Numero de testes para executar

	IN_FILE=$IN_FILEpre'_'$1'.txt'
	OUT_FILE=$OUT_FILEpre'_'$1'.txt'

	date
	date > $OUT_FILE
	echo Running $2 tests With: Type: $1 It: $ITERATIONS Th: $THREADS... >> $OUT_FILE
	echo "########## Running $2 tests With: Type: $1 It: $ITERATIONS Th: $THREADS ##########"

	STR_BASE_IN="$1 $ITERATIONS s"
	STR_IN="nop"
	
	if [[ $1 == D ]]
	then
		STR_IN="$STR_BASE_IN $BK_IN"
	else
		STR_IN="$STR_BASE_IN"
	fi
	
	# SEQUENTIAL
	echo $STR_IN > $IN_FILE	# Generates input file
	echo '########## Running sequential tests ##########' >> $OUT_FILE
	echo 'Sequential Tests - ' $1
	RunTests $2
	

	# PARALLEL
	for t in $THREADS
	do
		STR_BASE_IN="$1 $ITERATIONS p $t"
		if [[ $1 == D ]]
		then
			STR_IN="$STR_BASE_IN $BK_IN"
		else
			STR_IN="$STR_BASE_IN"
		fi
		echo $STR_IN > $IN_FILE	# Generates input file
		echo Running with $t threads...
		echo '########## Running parallel tests with' $t 'threads... ##########' >> $OUT_FILE
		echo 'Parallel Tests - ' $1
		RunTests $2
	done
	date >> $OUT_FILE
	date
}

# Testar Gauss Legendre
#PrepareAndRunTests A 0

# Testar Borwein
PrepareAndRunTests B 5

# Testar Monte Carlo
PrepareAndRunTests C 5

# Testar Black Scholes
PrepareAndRunTests D 5